package org.blogwu.learn.multithread.chapter3.demo11.v1;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MainV2 extends Thread {

    public MainV2(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(getName() + " start");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(100);
        // 这而的拒绝策略改为了new ThreadPoolExecutor.DiscardPolicy()  ,丢弃策略
        ThreadPoolExecutor th = new ThreadPoolExecutor(10, 20, 5, TimeUnit.SECONDS, arrayBlockingQueue, new ThreadPoolExecutor.DiscardPolicy());

        for (int i = 0; i < 121; i++) {
            th.submit(new MainV2("id: " + i));
        }
        Thread.sleep(10000);
        System.out.println("hello");
    }
}
